<%@page import="com.jspsmart.upload.Request"%>
<%@page import="com.jspsmart.upload.SmartUpload"%>
<%@page import="java.util.List"%>
<%@page import="cn.yunhe.model.Cate"%>
<%@page import="cn.yunhe.model.News"%>
<%@page import="cn.yunhe.biz.INewsBiz"%>
<%@page import="cn.yunhe.biz.NewsBizImpl"%>
<%@page import="cn.yunhe.model.Admin"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%	
	//实例化 SmartUpload
	SmartUpload su= new SmartUpload();
	//初始化
	su.initialize(pageContext);
	//设置编码方式
	su.setCharset("UTF-8");
	//允许上传的文件类型
	su.setAllowedFilesList("jpg,png,gif");
	su.upload();
	
	Request SmartRequest=  su.getRequest();
	su.save("pic");
	
	String title=SmartRequest.getParameter("title");
	String ccid=SmartRequest.getParameter("cid");
	String content = SmartRequest.getParameter("content");
	int cid=Integer.parseInt(ccid);
	
	//得到的文件名称
	String pic= su.getFiles().getFile(0).getFileName();
	
	Admin admin=(Admin)session.getAttribute("admin");
	
	INewsBiz newsBiz=new NewsBizImpl();
	
	News news=new News();
	news.setTitle(title);
	news.setContent(content);
	news.setPic(pic);
	
	Cate cate =new Cate();
	cate.setCateId(cid);
	
	news.setAdmin(admin);
	news.setCate(cate);
	
	boolean flag= newsBiz.addNews(news);
	List<News> newslist= newsBiz.getALLnew();
	 if(flag){
		 request.setAttribute("newslist", newslist);
		 request.getRequestDispatcher("listnews.jsp").forward(request, response);
	 }else{
		 response.sendRedirect("addNews.jsp");
	 }
	
	
	
%>